package org.eiahe.hr.salary.controller;

import lombok.RequiredArgsConstructor;
import org.ehe.common.core.BaseController;
import org.ehe.common.core.domain.R;
import org.ehe.common.log.annotation.Log;
import org.ehe.common.log.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.eiahe.hr.salary.service.IFinanceService;

/**
 * 财务Controller
 *
 * @author zhangnn
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/salary/finance")
public class FinanceController extends BaseController {

    @Autowired
    private IFinanceService financeService;

    /**
     * 生成银行代发文件
     *
     * @param yearMonth 年月
     */
    @SaCheckPermission("salary:finance:generateBankFile")
    @Log(title = "财务", businessType = BusinessType.OTHER)
    @PostMapping("/generateBankFile")
    public R<String> generateBankPaymentFile(@RequestParam String yearMonth) {
        String filePath = financeService.generateBankPaymentFile(yearMonth);
        if (filePath != null) {
            return R.ok("银行代发文件生成成功", filePath);
        } else {
            return R.fail("银行代发文件生成失败");
        }
    }

    /**
     * 生成工资凭证
     *
     * @param yearMonth 年月
     */
    @SaCheckPermission("salary:finance:generateVoucher")
    @Log(title = "财务", businessType = BusinessType.OTHER)
    @PostMapping("/generateVoucher")
    public R<String> generatePayrollVoucher(@RequestParam String yearMonth) {
        String filePath = financeService.generatePayrollVoucher(yearMonth);
        if (filePath != null) {
            return R.ok("工资凭证生成成功", filePath);
        } else {
            return R.fail("工资凭证生成失败");
        }
    }
}